<template>
  <div class="main-box">
    <el-form :model="expenseApplyForm" :rules="rules" ref="expenseApplyForm" label-width="100px" class="demo-ruleForm">
			<el-form-item label="申请账号" prop="leader_id">
			  <el-input v-model="expenseApplyForm.leader_id"></el-input>
			</el-form-item>
			
			<el-form-item label="所属活动" prop="type">
			  <el-select v-model="expenseApplyForm.type" placeholder="请选择" value="">
			    <el-option
			      v-for="activity in activities"
			      :key="activity.activityId"
			      :label="activity.activityName"
			      :value="activity.activityId"
			    />
			  </el-select>
			</el-form-item>
			<el-form-item label="所属社团" prop="club_id">
			  <el-select v-model="expenseApplyForm.club_id" placeholder="请选择" value="">
			    <el-option
			      v-for="community in communities"
			      :key="community.communityId"
			      :label="community.communityName"
			      :value="community.communityId"
			    />
			  </el-select>
			</el-form-item>
      <el-form-item label="借款金额" prop="jk_amount">
        <el-input v-model="expenseApplyForm.jk_amount"></el-input>
      </el-form-item>
      <el-form-item label="报销金额" prop="bx_amount">
        <el-input v-model="expenseApplyForm.bx_amount"></el-input>
				<!--这里可以加小项-->
      </el-form-item>
      <el-form-item label="报销说明" prop="file">
        <el-input v-model="expenseApplyForm.file"></el-input>
      </el-form-item>
      <el-form-item label="报销时间" required>
        <el-col :span="8">
          <el-form-item>
            <el-date-picker type="date" placeholder="选择日期"
                            style="width: 100%;" v-model="date1"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col class="line" :span="1">-</el-col>
        <el-col :span="8">
          <el-form-item prop="create_time">
            <el-time-picker placeholder="选择时间" v-model="expenseApplyForm.create_time"
                            style="width: 100%;"></el-time-picker>
          </el-form-item>
        </el-col>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('expenseApplyForm','leader_id')">确认报销</el-button>
        <el-button @click="resetForm('expenseApplyForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
	import localStorageUtil from "../../../utils/localStorageUtil";
    export default {
        data() {
            return {
				leader_id: localStorageUtil.read('SET_USER').userId,
				currentUser: localStorageUtil.read('SET_USER'),
                expenseApplyForm: {
                    id: '',
                    type: '',
                    club_id: '',
					leader_id: '',
                    jk_amount: '',
                    bx_amount: '',
                    file: '',
                    create_time: ''
                },
                date1: '',
                communities: [],
				activities: [],
                /*基础请求路径*/
                baseUrl: 'http://127.0.0.1:8888/community-management-service/',
                rules: {
                    type: [
                        {required: true, message: '请输入活动名称', trigger: 'blur'},
                    ],
                    club_id: [
                        {required: true, message: '请输入社团名称', trigger: 'blur'}
                    ],
                    jk_amount: [
                        {required: true, message: '请输入借款金额', trigger: 'blur'}
                    ],
                    bx_amount: [
                        {required: true, message: '请输入报销金额', trigger: 'blur'}
                    ],
                    file: [
                        {required: true, message: '请选择报销说明', trigger: 'change'}
                    ],
                    create_time: [
                        {type: 'date', required: true, message: '请选择时间', trigger: 'change'}
                    ]
                }
            };
        },
        created() {
            this.fetchCommunities()
			this.fetchActivities()
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$store.dispatch('expense/add', this.expenseApplyForm).then((res) => {
                            if (res.code === 200) {
                                this.$message({
                                    message: '发布成功',
                                    type: 'success'
                                });
                            }
                            this.resetForm(formName)
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            /*获取社团信息*/
            fetchCommunities() {
                this.$store.dispatch('community/findAll').then((res) => {
                    this.communities = res.data
                })
            },
			fetchActivities() {
				/*let param = {
				    userId: this.currentUser.userId
				}*/
				this.$store.dispatch('activity/find').then((res) => {
				    this.activities = res.data
				})
			}
        }
    }
</script>

<style>

  .disabled .el-upload--picture-card {
    display: none;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

  .main-box {
    margin: 2%;
  }
</style>
